/*
 * indicator.cpp
 *
 *  Created on: 16.07.2012
 *      Author: Roma Jam
 */

#include "stdint.h"
#include "stm32f10x.h"
#include "indicator.h"



void Indicator_t::Init(void) {
    GPIO_InitTypeDef  GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(INDICATOR_CLK, ENABLE);
    GPIO_InitStructure.GPIO_Pin = PIN_DN | PIN_DN_LEFT | PIN_DN_RIGHT | PIN_DOT | PIN_FIRST_SYMBOL | PIN_MIDDLE | PIN_SECOND_SYMBOL | PIN_UP | PIN_UP_LEFT | PIN_UP_RIGHT;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(INDICATOR_GPIO, &GPIO_InitStructure);
}

void Indicator_t::Light_Digit(uint8_t ADigit) {
    switch(ADigit) {
        case 0: {
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN_RIGHT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_MIDDLE);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP_RIGHT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP);
            break;
        }
        case 1: {
            GPIO_SetBits(INDICATOR_GPIO, PIN_DN);
            GPIO_SetBits(INDICATOR_GPIO, PIN_DN_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN_RIGHT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_MIDDLE);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP_RIGHT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_UP_LEFT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_UP);
            break;
        }
        case 2: {
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN_LEFT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_DN_RIGHT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_MIDDLE);
            GPIO_SetBits(INDICATOR_GPIO, PIN_UP_RIGHT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP);
            break;
        }
        case 3: {
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN);
            GPIO_SetBits(INDICATOR_GPIO, PIN_DN_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_DN_RIGHT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_MIDDLE);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP_RIGHT);
            GPIO_SetBits(INDICATOR_GPIO, PIN_UP_LEFT);
            GPIO_ResetBits(INDICATOR_GPIO, PIN_UP);
            break;
        }
        case 4: {
            GPIOB -> BSRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BRR = GPIO_Pin_5;
            GPIOD -> BSRR = GPIO_Pin_2;
            GPIOC -> BSRR = GPIO_Pin_13;
            GPIOC -> BRR = GPIO_Pin_1;
            GPIOC -> BRR = GPIO_Pin_0;
            break;
        }
        case 5: {
            GPIOB -> BRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BRR = GPIO_Pin_5;
            GPIOD -> BSRR = GPIO_Pin_2;
            GPIOC -> BRR = GPIO_Pin_13;
            GPIOC -> BSRR = GPIO_Pin_1;
            GPIOC -> BRR = GPIO_Pin_0;
            break;
        }
        case 6: {
            GPIOB -> BRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BRR = GPIO_Pin_5;
            GPIOD -> BRR = GPIO_Pin_2;
            GPIOC -> BRR = GPIO_Pin_13;
            GPIOC -> BSRR = GPIO_Pin_1;
            GPIOC -> BRR = GPIO_Pin_0;
            break;
        }
        case 7: {
            GPIOB -> BSRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BSRR = GPIO_Pin_5;
            GPIOD -> BSRR = GPIO_Pin_2;
            GPIOC -> BRR = GPIO_Pin_13;
            GPIOC -> BRR = GPIO_Pin_1;
            GPIOC -> BSRR = GPIO_Pin_0;
            break;
        }
        case 8: {
            GPIOB -> BRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BRR = GPIO_Pin_5;
            GPIOD -> BRR = GPIO_Pin_2;
            GPIOC -> BRR = GPIO_Pin_13;
            GPIOC -> BRR = GPIO_Pin_1;
            GPIOC -> BRR = GPIO_Pin_0;
            break;
        }
        case 9: {
            GPIOB -> BRR = GPIO_Pin_7;
            GPIOB -> BRR = GPIO_Pin_6;
            GPIOB -> BRR = GPIO_Pin_5;
            GPIOD -> BSRR = GPIO_Pin_2;
            GPIOC -> BRR = GPIO_Pin_13;
            GPIOC -> BRR = GPIO_Pin_1;
            GPIOC -> BRR = GPIO_Pin_0;
            break;
        }
        default: {
            GPIOB -> BSRR = GPIO_Pin_7;
            GPIOB -> BSRR = GPIO_Pin_6;
            GPIOB -> BSRR = GPIO_Pin_5;
            GPIOD -> BSRR = GPIO_Pin_2;
            GPIOC -> BSRR = GPIO_Pin_13;
            GPIOC -> BSRR = GPIO_Pin_1;
            GPIOC -> BSRR = GPIO_Pin_0;
            break;
        }
    }
}
